package com.bizmerce.rnd.oms.judgment.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.bizmerce.rnd.oms.decision.CriterionManager;
import com.bizmerce.rnd.oms.decision.criterion.Criterion;
import com.bizmerce.rnd.oms.decision.data.BillOfMaterials;
import com.bizmerce.rnd.oms.decision.data.DeMinimis;
import com.bizmerce.rnd.oms.decision.data.FreeTradeAgreement;
import com.bizmerce.rnd.oms.decision.data.PsrCriterion;
import com.bizmerce.rnd.oms.decision.data.TestData;
import com.bizmerce.rnd.oms.judgment.service.JuSearchVO;
import com.bizmerce.rnd.oms.judgment.service.JudgmentService;
import com.bizmerce.rnd.oms.judgment.service.JudgmentVO;

@Service("judgmentService")
public class JudgmentServiceImpl implements JudgmentService{
	/**
	 * ERP로부터 BOM을 가져온다.
	 * 협정정보가 'Y'인 협정을 포함한 BOM을 몽땅 가져온다.
	 * @param bom
	 */
	public void makeDecision(BillOfMaterials[] boms) {
		for (BillOfMaterials bom : boms) {
			FreeTradeAgreement fta = bom.getFta();
			List<PsrCriterion> psrCriterions = fta.getPsrCriterion(bom.getHsCode());
			DeMinimis deMinimis = fta.getDeMinimisRate(bom.getHsCode());
			
			CriterionManager criterionManager = new CriterionManager();
			for (PsrCriterion psrCriterion : psrCriterions) {
				Criterion criterion = criterionManager.getCreterion(psrCriterion, deMinimis);
				boolean result = criterion.assign(bom);
				System.out.println("Result:" + result);
			}
		}
	}
	
	public static void main(String[] args) {
		JudgmentServiceImpl j = new JudgmentServiceImpl();
		j.makeDecision(new BillOfMaterials[]{TestData.getBOM()});
	}
	
	@Resource(name = "judgmentDAO")
	JudgmentDAO judgmentDAO;
	
	/**
	 * 판정이력정보
	 * 
	 * 검색 조건 : Part No.
	 * @
	 */
	public List<JudgmentVO> selectJudgment(JuSearchVO searchVO)  {
		return judgmentDAO.selectJudgment(searchVO);
	}

	/**
	 * 
	 */
	public int selectJudgmentCount(JuSearchVO searchVO)  {
		return judgmentDAO.selectJudgmentCount(searchVO);
	}

	public JudgmentVO selectConfirm(String decisionNum) {
		return judgmentDAO.selectConfirm(decisionNum);
	}
}